package com.wyl.rpc.config.provider;

import com.wyl.rpc.server.RpcServer;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @author: wyl
 * @date: 2021/8/17
 * @des:
 */
@Slf4j
public class RpcServerConfig {

    private final String host = "127.0.0.1";

    protected int port;

    private List<ProviderConfig> providerConfigs;

    private RpcServer rpcServer = null;

    public RpcServerConfig(List<ProviderConfig> providerConfigs) {
        this.providerConfigs = providerConfigs;
    }

    public void exporter() {
        if (rpcServer == null) {
            try {
                rpcServer = new RpcServer(host + ":" + port);
            } catch (Exception e) {
                log.error("RpcServerConfig exporter exception: ", e);
            }

            for (ProviderConfig providerConfig : providerConfigs) {
                rpcServer.registerProcessor(providerConfig);
            }
        }
        // TODO 把所有服务提供的列表注册到zk上
        /**
         *	/dubbo
         *		/interface: com.bfxy.service.HelloService
         *			/providers
         *				/ip:port (192.168.11.101:8765)
         *				/ip:port (192.168.11.102:8765)
         *			/consumers
         * 				/ip:port
         * 				/ip:port
         */
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public List<ProviderConfig> getProviderConfigs() {
        return providerConfigs;
    }

    public void setProviderConfigs(List<ProviderConfig> providerConfigs) {
        this.providerConfigs = providerConfigs;
    }
}
